package com.ruoyi.common.core.utils;

/**
 * @author liyang
 * @description
 * @date 2022-11-22 10:43:12
 */
public class CamelCaseUtil {

    public static String toCamelCase(String name) {
        if (null == name) {
            return null;
        } else {
            String name2 = name.toString();
            if (name2.contains("_") || name2.contains("-")) {
                StringBuilder sb = new StringBuilder(name2.length());
                boolean upperCase = false;

                for (int i = 0; i < name2.length(); ++i) {
                    char c = name2.charAt(i);
                    if (c == '_' || c == '-') {
                        upperCase = true;
                    } else if (upperCase) {
                        sb.append(Character.toUpperCase(c));
                        upperCase = false;
                    } else {
                        sb.append(Character.toLowerCase(c));
                    }
                }

                return sb.toString();
            } else {
                return name2;
            }
        }
    }

}
